var app = getApp();
import LoadMore from '../../../utils/LoadMore.js'
var load = new LoadMore;
var util = require('../../../utils/util.js');

Page({
  data: {
    url: app.globalData.setting.url,
    resourceUrl: app.globalData.setting.resourceUrl,
    withdrawals: null, //请求的充值记录
    currentPage: 1,
    type: 0,
    total: 0,
    withdraw: 0
  },

  onLoad: function (options) {
    if (options && options.type) {
      this.setData({
        type: options.type,
        total: options.total,
        withdraw: options.withdraw
      })
      console.log(options)
    }
    load.init(this, '', 'withdrawals');
    this.requestWithdrawalsList();
  },

  requestWithdrawalsList: function () {
    var that = this;
    var requestUrl = '/api/User/account_distribut_log?page=' + that.data.currentPage;
    load.request(requestUrl, function (res) {
      that.data.currentPage++;
      res.data.result.forEach(function (val, index, arr) {
        val.createTimeFommat = util.format(val.change_time, 'yyyy-MM-dd hh:mm');
      });
      wx.stopPullDownRefresh();
      // that.setData({
      //   withdrawals: [{
      //     id: 1,
      //     createTimeFommat: '2025-5-6',
      //     money: '200',
      //     status: 1
      //   },{
      //     id: 2,
      //     createTimeFommat: '2025-5-6',
      //     money: '200',
      //     status: 2
      //   },{
      //     id: 3,
      //     createTimeFommat: '2025-5-6',
      //     money: '200',
      //     status: 3
      //   }]
      // })
    });
  },

  onReachBottom: function () {
    if (load.canloadMore()) {
      this.requestWithdrawalsList();
    }
  },

  onPullDownRefresh: function () {
    this.data.withdrawals = null;
    this.data.currentPage = 1;
    load.resetConfig();
    this.requestWithdrawalsList();
  }

});